package com.network.controller;

import com.network.pojo.Result;
import com.network.pojo.User;
import com.network.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/add")
    public Result add(@RequestBody User user) {
        log.info("add user");
        try {
            userService.add(user);
        } catch (Exception e) {
            return Result.error("用户名重复");
        }
        return Result.success();
    }
}
